//
//  TPAppointDetailViewController.m
//  Yimei
//
//  Created by xiaowu xiaowu on 2017/10/28.
//  Copyright © 2017年 xiaowu xiaowu. All rights reserved.
//

#import "TPAppointDetailViewController.h"
#import "TPAppointmentCell.h"
#import "TPAppointDetailCell.h"
@interface TPAppointDetailViewController ()
@property (nonatomic,strong)UIView *tabbarView;
@end

@implementation TPAppointDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"护理记录";
    [self sepTabbar];
    self.tableViewStyle = UITableViewStyleGrouped;
    self.tableView.backgroundColor = [UIColor whiteColor];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.tableView reloadData];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return section == 0 ? 1 :6;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if(indexPath.section == 1){
        TPAppointDetailCell *cell =[tableView dequeueReusableCellWithIdentifier:@"TPAppointDetailCell"];
        if(!cell){
            cell = [[TPAppointDetailCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"TPAppointDetailCell"];
        }
        
        cell.model = self.model;
        return cell;
    }
    
    TPAppointmentCell *cell =[tableView dequeueReusableCellWithIdentifier:@"cellx"];
    if(!cell){
        cell = [[TPAppointmentCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cellx"];
    }
    cell.type = TPAppointmentTypeAppoint;
    cell.model = self.model;
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return section == 0 ? 0.01f:44.0;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return section == 0 ? nil:self.tabbarView;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.01f;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}



-(void )sepTabbar{
    
    
    UIView *tabbarView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, IPHONE_WIDTH, 44.0)];
    _tabbarView = tabbarView;
    
    UIView *tabbar = [[UIView alloc]initWithFrame:CGRectMake(15, 0, IPHONE_WIDTH-30, 44.0)];
    tabbar.backgroundColor = tabbarView.backgroundColor =  [UIColor whiteColor];
    [tabbarView addSubview:tabbar];
   
    
    
    UIButton *resetButton = [UIButton buttonWithFrame:CGRectZero title:@"护理时间" font:fontSystemOfSize(17) color:TPAllBackgroundColor];
    resetButton.selected = YES;
    [tabbar addSubview:resetButton];
    
    
    UIButton *doneButton = [UIButton buttonWithFrame:CGRectZero title:@"负责人" font:fontSystemOfSize(17) color:TPAllBackgroundColor];
    [tabbar addSubview:doneButton];
    
    [resetButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.bottom.mas_equalTo(0.0);
        make.width.mas_equalTo(tabbar.mas_width).multipliedBy(0.5);
    }];
    [doneButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.top.bottom.mas_equalTo(0.0);
        make.width.mas_equalTo(resetButton.mas_width);
    }];
    
    [tabbar tp_addLineBottomWithColor:TP_COLOR_240];
    [tabbar tp_addLineTopWithColor:TP_COLOR_240];
    
    UIImageView *line = [[UIImageView alloc]init];
    line.backgroundColor = TP_COLOR_240;
    [tabbar addSubview:line];
    [tabbar bringSubviewToFront:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(tabbar.mas_centerX);
        make.height.mas_equalTo(tabbar.mas_height).multipliedBy(0.7);
        make.centerY.mas_equalTo(tabbar);
        make.width.mas_equalTo(1.5);
    }];
}

@end
